class Solution {
    public ListNode removeElements(ListNode head, int val) {
        if(head == null){
            return null;
        }
        ListNode newhead = new ListNode();
        ListNode cur = newhead;
        cur.next = head;
        while(cur.next!=null){
            if(cur.next.val == val){
                cur.next = cur.next.next;
            }
            else
                cur = cur.next;

        }
        return newhead.next;
    }
}